package com.learn.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

//在访问数据库时会调用该类的
public class DataSourceRoutingDataSource extends AbstractRoutingDataSource {

    private final Logger log = LoggerFactory.getLogger(getClass());

    //获取数据库实例的 key
    @Override
    protected Object determineCurrentLookupKey() {
        log.info("Current DataSource is [{}]",DynamicDataSourceContextHolder.getDataSourceKey());
        return DynamicDataSourceContextHolder.getDataSourceKey();
    }
}
